<template>
  <div>
    <el-tree :data="depts" :props="defaultProps" default-expand-all />
  </div>
</template>

<script>
import { getDepartmentsAPI } from '@/api/department'
import { transListToTreeData } from '@/utils'
export default {
  data() {
    return {
      depts: [],
      defaultProps: {
        label: 'name',
        children: 'children'
      }
    }
  },
  created() {
    this.getDepartment()
  },
  methods: {
    async getDepartment() {
      this.depts = transListToTreeData(await getDepartmentsAPI(), 0)
    }
  }
}
</script>

<style>

</style>
